import {fakerZH_CN as faker} from '@faker-js/faker';

const fullName = faker.person.fullName();

const createBasicInfo = () => {
    // 先生成 orderShow
    const allKeys = [
        // "avatar",
        "fullName",
        "gender",
        "phone",
        "email",
        "wxNumber",
        "address",
        "inWorkTime",
        "birthDay",
        "desireCity",
        "desirePosition",
        "salary",
        "nativePlace",
        "politicalOutlook",
        "education",
    ]
    const orderShow = [
        "fullName",
        ...faker.helpers.arrayElements(allKeys, {
            max: 14,
            min: 6
        })
    ]
    // 根据 orderShow 生成数据
    const generateData: any = {
        // avatar: faker.image.avatar(),
        fullName,
        gender: faker.helpers.arrayElement([1, 2]),
        phone: faker.phone.number(),
        email: faker.internet.email(),
        wxNumber: faker.internet.userName(),
        address: faker.location.city(),
        inWorkTime: faker.date.past(),
        birthDay: faker.date.birthdate(),
        desireCity: faker.location.city(),
        desirePosition: faker.person.jobTitle(),
        salary: faker.finance.amount(),
        nativePlace: faker.location.city(),
        politicalOutlook: faker.helpers.arrayElement([1, 2, 3, 4]),
        education: faker.helpers.arrayElement([1, 2, 3, 4, 5]),
    }
    const data = orderShow.reduce((acc: any, cur: any) => {
        return {
            ...acc,
            [cur]: generateData[cur]
        }
    }, {})


    return {
        _id: faker.string.uuid(),
        title: "基础信息",
        orderShow,
        ...data,
    };
}

const createDetailInfo = () => {
    const allKeys: any = {
        work: {
            title: "工作经验",
            classify: "EXPERIENCE"
        },
        project: {
            title: "项目经验",
            classify: "EXPERIENCE"
        },
        education: {
            title: "教育经历",
            classify: "EXPERIENCE"
        },
        internship: {
            title: "实习经历",
            classify: "EXPERIENCE"
        },
        volunteer: {
            title: "志愿经历",
            classify: "EXPERIENCE"
        },
        society: {
            title: "社团经历",
            classify: "EXPERIENCE"
        },
        advantage: {
            title: "个人优势",
            classify: "OTHERS"
        },
        certificate: {
            title: "证书",
            classify: "OTHERS"
        },
        skill: {
            title: "技能",
            classify: "OTHERS"
        },
        evaluation: {
            title: "自我评价",
            classify: "OTHERS"
        },
        hobby: {
            title: "兴趣爱好",
            classify: "OTHERS"
        },
    }
    return Object.keys(allKeys).map((key) => {
        return {
            title: allKeys[key]?.title,
            type: key,
            classify: allKeys[key].classify,
            isShow: faker.datatype.boolean(),
            value: allKeys[key]?.classify === 'EXPERIENCE' ?
                Array.from({length: faker.number.int(3)}).map(() => {
                    return {
                        name: faker.company.name(),
                        position: faker.person.jobTitle(),
                        startTime: faker.date.past(),
                        endTime: faker.date.past(),
                        content: faker.lorem.paragraphs(),
                        result: faker.lorem.paragraphs(),
                    }
                })
                :
                faker.lorem.paragraphs()
        }
    })
}

const createData = () => {
    return {
        cvName: fullName + '的简历',
        basicInfo: createBasicInfo(),
        detailInfo: createDetailInfo(),
    };
}

export default createData;




